package com.lingnan.eduservice.controller;


import com.lingnan.common.utils.ResultEntity;
import com.lingnan.eduservice.entity.vo.EduOneSubjectVO;
import com.lingnan.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author zzd
 * @Api : 开发文档注解
 * @RestController : ResponseBody + Controller
 * @RequestMapping : 请求路径 /eduservice/edusubject
 * @CrossOrigin : 解决跨域问题
 * @since 2021-08-16
 */
@Api(description = "课程管理")
@RestController
@RequestMapping("/eduservice/edusubject")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectServicel;

    /**
     * 批量导入课程信息
     * @param file 课程Excel文件
     * @return
     */
    @ApiOperation(value = "Excel批量导入课程")
    @PostMapping("addSubjectByExcel")
    public ResultEntity addSubjectByExcel(MultipartFile file){

        eduSubjectServicel.addSubjectByExcel(file,eduSubjectServicel);

        return ResultEntity.ok();
    }

    /**
     * 查询所有课程信息(树形展示)
     * @return
     */
    @ApiOperation(value = "查询所有课程信息(树形展示)")
    @GetMapping("findAllSubjectByTree")
    public ResultEntity findAllSubjectByTree(){

        // 调用Service执行一对多查询
        List<EduOneSubjectVO> subjectVOList = eduSubjectServicel.findAllSubjectByTree();

        return ResultEntity.ok().data("subjectVOList",subjectVOList);
    }

}

